import Tools.Tools
from config.config import config
from Tools.Tools import yaml_data,log
import pytest

class Test_Case:
    Cookie=None
    @pytest.fixture(scope="session")
    def api(self):
        Tools.Tools.log()
        return config()

    #传入正确参数，添加成功
    @pytest.mark.parametrize('data',yaml_data('D:\桌面\guoqing1\yaml.yaml'))
    def test_01_add(self,api,data):
        try:
            header={
                "cookie":"RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type":"application/x-www-form-urlencoded; charset=UTF-8"
            }
            body={
                "consignee": data['consignee'],
                "province": data['province'],
                "city": data['city'],
                "district": data['district'],
                "street": data['street'],
                "addressMore": data['addressMore'],
                "mobile": data['mobile'],
                "phone":data['phone'],
                "addressName": data['addressName']

            }
            login=api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=header
            )

            print(login.json())
            assert login.status_code == 200
        except Exception as e:
            print(e)

    # 传入已存在地址的参数，添加失败，提示地址已存在
    def test_02_add(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
                "consignee": "增加",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "asdadas",
                "mobile": "13604100265",
                "phone": "",
                "addressName": "福建省-福州市-台江区"

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )

            print(login.json())
            assert login.status_code == 200
        except Exception as e:
            print(e)

    #用户未登录添加地址，添加失败
    def test_03_add(self, api):
        try:
            headers = {
                "cookie": "",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
                "consignee": "增加",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "asdadas",
                "mobile": "13604100265",
                "phone": "",
                "addressName": "福建省-福州市-台江区"

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )

            print(login.json())
            assert login.status_code == 200
        except Exception as e:
            print(e)
    #删除已存在的地址，删除成功
    def test_04_delete(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
               "id":"117703480"
            }
            delete= api.post(
                path='myaccount/deleteAddress.htm',
                data=body,
                headers=headers
            )

            print(delete.json())
            assert delete.status_code == 200
        except Exception as e:
            print(e)
    #未登录删除地址，删除失败
    def test_05_delete(self, api):
        try:
            headers = {
                "cookie": "",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
               "id":"117703480"
            }
            delete= api.post(
                path='myaccount/deleteAddress.htm',
                data=body,
                headers=headers
            )

            print(delete.json())
            assert delete.status_code == 200
        except Exception as e:
            print(e)

        #修改已存在地址，修改成功
    def test_06_gai(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
                "id": "117703476",
                "consignee": "李四",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "asdadas",
                "mobile": "13604100265",
                "phone": "",
                "addressName": "福建省-福州市-台江区"

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )
            assert login.status_code == 200
        except Exception as e:
            print(e)
        #修改地址为其他已存在地址，修改失败
    def test_07_gai(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
                "id": "117703476",
                "consignee": "张三",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "asdadas",
                "mobile": "13604100265",
                "phone": "",
                "addressName": "福建省-福州市-台江区"

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )

            assert login.status_code == 200
        except Exception as e:
            print(e)
    #参数ID为错误ID时,提示改地址不存在
    def test_08_gai(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
                "id": "1177@@3476",
                "consignee": "张三",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "asdadas",
                "mobile": "13604100265",
                "phone": "",
                "addressName": "福建省-福州市-台江区"

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )
            assert login.status_code == 200
        except Exception as e:
            print(e)

    #不填写详细地址，地址修改失败
    def test_09_gai(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {
                "id": "11773476",
                "consignee": "张三",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "",
                "mobile": "13604100265",
                "phone": "",
                "addressName": ""

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )
            assert login.status_code == 200
        except Exception as e:
            print(e)
    #缺少参数phone，地址修改失败
    def test_010_gai(self, api):
        try:
            headers = {
                "cookie": "RandomTest=0.951453426003227; NTKF_T2D_CLIENTID=guest9A8EA66B-1424-BBA5-C941-4FC8B647CB46; JX_TID=251f7992-7cae-1452-96ca-7320ffa4f839; _jzqx=1.1753685209.1757034299.14.jzqsr=cn%2Ebing%2Ecom|jzqct=/.jzqsr=cn%2Ebing%2Ecom|jzqct=/; SearchUserKey=7a67a57f-f0f4-169c-a85b-aaaa8edc6f25; user_province=2; _jzqa=1.2249911212438285000.1753685209.1757346975.1759463379.29; _jzqc=1; _jzqckmp=1; nTalk_CACHE_DATA={uid:jx_1000_ISME9754_guest9A8EA66B-1424-BB,tid:1759463379394510}; _jzqb=1.1.10.1759463379.1; PTOKEN=877F384F7D5A0FEF004B97C417CDAB9C; JSESSIONID=A7116B2715DEF6DB0D3B0F7FB6017647; __ozlvd1722=1759463409; testcookie=yes; JX_SID=423fbbd4-4e78-160f-b395-0e7d9d755977; _fmdata=%2Fu%2Fx%2F6NiOJKxeZ4STf3EKVuMvDd8Vj83fADb00cROxncMUoBd0bVUyytUyNj3nJKU83pTMQhNjd7cv0HayEpkTxGwuYw%2FOCxAWvdp1q2QbI%3D",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            body = {

                "consignee": "张三",
                "province": "4",
                "city": "53",
                "district": "519",
                "street": "0",
                "addressMore": "",
                "mobile": "13604100265",

                "addressName": ""

            }
            login = api.post(
                path='myaccount/saveAddress.htm',
                data=body,
                headers=headers
            )
            assert login.status_code == 200
        except Exception as e:
            print(e)
if __name__ == '__main__':
    pytest.main()




